package nowcoder;

import java.io.*;
import java.util.*;

public class D_68_dijkstra {
    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));
    static final int N = 310, INF = 0x3f3f3f3f;
    static int[][] g = new int[N][N];
    static int t;
    static int[] d = new int[N];
    static boolean[] st = new boolean[N];

    static int cin() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    static void dijkstra() {
        Arrays.fill(d, INF);
        d[10] = 0;
        for (int i = 0; i < N - 1; i ++ ) {
            int t = -1;
            for (int j = 1; j < N; j ++ ) {
                if (!st[j] && (t == -1 || d[t] > d[j])) {
                    t = j;
                }
            }
            for (int j = 1; j < N; j ++ ) {
                d[j] = Math.min(d[j], d[t] + g[t][j]);
            }
            st[t] = true;
        }
    }

    public static void main(String[] args) throws IOException {
        for (int i = 0; i < N; i ++ ) {
            Arrays.fill(g[i], INF);
            g[i][300] = 1;
            g[i][10] = 1;
            g[i][i] = 0;
        }
        for (int i = 0; i < N; i ++ ) {
            if (i + 1 < N) {
                g[i][i + 1] = Math.min(g[i][i + 1], 1);
                g[i + 1][i] = Math.min(g[i + 1][i], 1);
            }
            if (i - 1 >= 0) {
                g[i][i - 1] = Math.min(g[i][i - 1], 1);
                g[i - 1][i] = Math.min(g[i - 1][i], 1);
            }
            if (i + 10 < N){
                g[i][i + 10] = Math.min(g[i][i + 10], 1);
                g[i + 10][i] = Math.min(g[i + 10][i], 1);
            }
            if (i - 10 >= 0) {
                g[i][i - 10] = Math.min(g[i][i - 10], 1);
                g[i - 10][i] = Math.min(g[i - 10][i], 1);
            }
            if (i + 100 < N) {
                g[i][i + 100] = Math.min(g[i][i + 100], 1);
                g[i + 100][i] = Math.min(g[i + 100][i], 1);
            }
            if (i - 100 >= 0) {
                g[i][i - 10] = Math.min(g[i][i - 100], 1);
                g[i - 10][i] = Math.min(g[i - 100][i], 1);
            }
        }
        dijkstra();
        t = cin();
        while (t -- > 0) {
            int a = cin(), b = cin(), c = cin(), dd = cin();
            out.println(d[a] + d[b] + d[c] + d[dd]);
        }
        out.flush();
    }
}